open Ocamlbuild_plugin ;;
open Command;;

(* set the version number of the software in the plugin *)
(* let project = "rot" *)
(* let major = 0 *)
(* let minor = 1 *)
(* let patch = 0                           (\* patch level *\) *)
(* let tag   = ""                          (\* build tag *\) *)

(* (\* generate src/version.ml in the plugin *\) *)
(* let version_ml = "src/version.ml" *)
(* let version_file_contents = *)
(*   let buf = Buffer.create 255 in *)
(*   Printf.bprintf buf "(\* This file is automatically generated!\n" ; *)
(*   Printf.bprintf buf "   To change version numbers, edit myocamlbuild.ml *\)\n" ; *)
(*   Printf.bprintf buf "let major = %d;;\n" major ; *)
(*   Printf.bprintf buf "let minor = %d;;\n" minor ; *)
(*   Printf.bprintf buf "let patch = %d;;\n" patch ; *)
(*   Printf.bprintf buf "let tag   = \"%s\";;\n" tag ; *)
(*   Printf.bprintf buf "let str   = \"%d.%d.%d%s%s\";;\n" *)
(*     major minor patch *)
(*     (if tag = "" then "" else "-") tag ; *)
(*   Buffer.contents buf *)
(* let make_version msg = *)
(*   Printf.printf "(Re)Generating %S...%!" version_ml ; *)
(*   let ch = open_out version_ml in *)
(*   output_string ch version_file_contents ; *)
(*   close_out ch ; *)
(*   Printf.printf " done.\n%!" *)


let () =
  Options.use_ocamlfind := true ;
  Options.use_menhir := true ;
  (* make_version () *)
;;


let alphaCaml = A"alphaCaml";;

(* the entry point of the plugin *)
let _ =
  dispatch begin function
    | After_rules ->
      flag ["ocaml" ; "compile"] (A "-annot") ;
      flag ["ocaml" ; "compile"] (A "-g") ;
      flag ["ocaml" ; "compile"; "native" ] (S [(A "-inline"); (A "20")]) ;

      (* for alphaCaml *)
      rule "alphaCaml: mla -> ml & mli"
        ~prods:["%.ml"; "%.mli"]
        ~dep:"%.mla"
      begin fun env _build ->
        Cmd(S[alphaCaml; P(env "%.mla")])
      end
    | _ -> ()
  end
